<include file="Public/siteTopbar" />
<link rel="stylesheet" href="__STATIC__/css/user.css" type="text/css">
<include file="Public/header" />


<div class="container logintop">
<h3>My Account</h3>
<p>My Account allows you to manage your setting and preferences. Existing wish list or project portfolio logins can be used to login to My Account.</p>
</div>


<div class="container usercenter">
    <div class="col-sm-6">
        <div class="longinBox">
            <h3>- LOG IN TO ACCOUNT -</h3>
             <form action="{:U('Home/User/do_login')}" method="post">
            <input type="hidden" name="referurl" id="referurl" value="{$referurl}">
            <ul class="form-list">
            <li>
            <label for="email" class="required"><em>*</em>Email Address</label>
            <input type="text" id="username" name="username"  onKeyDown="if(event.keyCode==13){checkSubmit();}" value="" class="loginInput required-entry validate-email" title="Email Address">
            </li>
            <li>
            <label for="pass" class="required"><em>*</em>Password</label>
            <input type="password" name="password" id="password"  onKeyDown="if(event.keyCode==13){checkSubmit();}"  class="loginInput required-entry validate-password" id="pass" title="Password">
            </li>


            <li><a  href="{:U('User/forget_pwd')}"   class="f-left">Forgot Your Password?</a></li>
            <li><button type="button" class="loginbutton"  onClick="checkSubmit()" title="Login" name="send" id="send2"><span><span>Login</span></span></button></li>
            </ul>
                        </form>
        </div>
    </div>
    <div class="col-sm-6">
        <div class="longinBox" style="min-height:416px;">
            <h3>- CREATE AN ACCOUNT -</h3>
            			          <form action="" method="post" onSubmit=" return check_submit(this)" id="reg_form">

            <ul class="form-list">
                <li class="fields">
        <label for="firstname" class="required"><em>*</em>First Name</label>
            <input type="text" id="firstname" name="firstname" value="" title="First Name" class="loginInput required-entry">
   </li>
   <li>
        <label for="lastname" class="required"><em>*</em>Last Name</label>
            <input type="text" id="lastname" name="lastname" value="" title="Last Name" class="loginInput required-entry">

</li>
                </li>
                <li>
                    <label for="email_address" class="required"><em>*</em>Email Address</label>
                        <input type="text" name="usernamereg" id="usernamereg" value="" title="Email Address" class="loginInput validate-email required-entry">

                </li>
                <!--<li style=" position:relative;">-->
                    <!--<label for="email_address" class="required"><em>*</em>Code</label>-->
                        <!--<input type="text" name="code" id="code" value=""  class="loginInput validate-email required-entry">-->
                    <!--<button type="button" class="po-ab to0" style="width: 80px;height:38px;border:none; background:#630534; color:#fff; position:absolute; right:0; top:36px; border-radius:0 5px 5px 0;" id="count_down" onClick="send_smtp_reg_code()">Send</button>-->
                <!--</li>-->


                                                                                                  <li>
                    <label for="password" class="required"><em>*</em>Password</label>
                        <input type="password" name="password" id="password" title="Password" class="loginInput required-entry validate-password">
                </li>
                <li>
                    <label for="confirmation" class="required"><em>*</em>Confirm Password</label>
                        <input type="password" name="password2" title="Confirm Password" id="password2" class="loginInput required-entry validate-cpassword">
                </li>
				                <li class="control" style="display:none;">
                         <label for="is_subscribed"><input type="checkbox" name="is_subscribed" title="Sign Up for Newsletter" value="1" id="is_subscribed" class="checkbox">

                   Sign Up for Newsletter</label>
                </li>
                                              <li><button type="submit" class="loginbutton" title="Login" name="send" id="send2"><span><span>CREATE ACCOUNT</span></span></button></li>
            </ul>

            </form>

        </div>
    </div>
</div>


<include file="Public/footer01" />

<script>

    flag = true;
    $(document).ready(function(){

        $("input[name='usernamereg']").blur(function () {
            var username = $(this).val();
        	var reg = /^[a-z0-9]([a-z0-9\\.]*[-_]{0,4}?[a-z0-9-_\\.]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+([\.][\w_-]+){1,5}$/i;
            if (reg.test(username)) {
                $.ajax({
                    type : "GET",
                    url:"/index.php?m=Home&c=Api&a=issetMobileOrEmail",//+tab,
                    data :{mobile:username},// 你的formid 搜索表单 序列化提交
                    success: function(data)
                    {
                        if(data != '0')
                        {
                            flag = false;
                        }else{
                            flag = true;
                        }
                    }
                });
            }else{
                flag = false;
            }
        })
    });
</script>
<script>
	 function check_submit(obj){

        var firstname = $(obj).find('input[name="firstname"]').val();
        var lastname = $(obj).find('input[name="lastname"]').val();
        var username = $(obj).find('input[name="usernamereg"]').val();
//        var code = $(obj).find('input[name="code"]').val();
        var password = $(obj).find('input[name="password"]').val();
        var password2 = $(obj).find('input[name="password2"]').val();
      //  var verify_code = $(obj).find('input[name="verify_code"]').val();
        //var agree = $(obj).find('input[type="checkbox"]:checked').val();
        var error = '';
        if(firstname == ''){
			layer.msg('First Name is a required field.', {
				icon: 1,
				time: 2000
			});
			return false;
        }
        if(lastname == ''){
			layer.msg('Last Name is a required field.', {
				icon: 1,
				time: 2000
			});
			return false;
        }
        if(username == ''){
			layer.msg('Email Address is a required field.', {
				icon: 1,
				time: 2000
			});
			return false;
        }

		if(!checkEmail(username)){
		   layer.msg('Email Address format is incorrect.', {
				icon: 1,
				time: 2000
			});
            return false;
        }

//        if(code == ''){
//			layer.msg('Code is a required field.', {
//				icon: 1,
//				time: 2000
//			});
//			return false;
//        }

        if(password == '' || password2 == ''){

			layer.msg('Password is a required field.', {
				icon: 1,
				time: 2000
			});
			return false;
        }

        if(password !== password2){

			layer.msg('Enter the password twice inconsistent.', {
				icon: 1,
				time: 2000
			});
			return false;
        }
        if(password.length < 6){
			layer.msg('Password length can not be less than 6.', {
				icon: 1,
				time: 2000
			});
			return false;
        }

        if(!flag){
			layer.msg('Email Address Already registered.', {
				icon: 1,
				time: 2000
			});
			return false;
        }
		/*
        if(error){
           layer.alert(error, {icon: 2});// alert(error);
            return false;
        }*/
        return true;
    }


	// 发送邮箱验证
    function send_smtp_reg_code(){
        var email = $("input[name='usernamereg']").val();
        if(!checkEmail(email)){
		   layer.msg('Email Address format is incorrect.', {
				icon: 1,
				time: 2000
			});
            return;
        }
        $.ajax({
            type : "POST",
            url:"{:U('Home/User/send_validate_code')}",
            data : {type:'email',send:email},// 你的formid
            dataType: "json",
            success: function(data){
                if(data.status){
                    $('#count_down').attr("disabled","disabled");
                    $('#count_down').css("background-color","#000000");
                    intAs = {$sms_time_out}; // 发送邮箱
                    jsInnerTimeout('count_down',intAs);
                }
                layer.alert(data.msg+', Attention: this mail maybe placed in junk mail.', {icon: 1});// alert(obj.msg);
            }
        });

    }

	function jsInnerTimeout(id,intAs)
    {
        var codeObj=$("#"+id);
        //var intAs = parseInt(codeObj.attr("IntervalTime"));

        intAs--;
        if(intAs<=-1)
        {
            codeObj.removeAttr("disabled");
			codeObj.css("background-color","#630534");
//            codeObj.attr("IntervalTime",60);
            codeObj.text("Send");
            return true;
        }

        codeObj.text(intAs+'s');
//        codeObj.attr("IntervalTime",intAs);

        setTimeout("jsInnerTimeout('"+id+"',"+intAs+")",1000);
    };

	function checkSubmit()
	{
		var username = $.trim($('#username').val());
		var password = $.trim($('#password').val());
		var referurl = $('#referurl').val();
		//var verify_code = $.trim($('#verify_code').val());
		if(username == ''){

			 		layer.msg('Email Address is a required field.', {
                            icon: 1,
                            time: 2000
                        });
						return false;
		}
		if(!checkEmail(username)){

			 		layer.msg('Email Address is format does not match.', {
                            icon: 1,
                            time: 2000
                        });
			return false;
		}
		if(password == ''){
layer.msg('Password is a required field.', {
                            icon: 1,
                            time: 2000
                        });
						return false;
		}
		/*if(verify_code == ''){
			alert('驗證碼不能為空');
			return false;
		}*/

		$.ajax({
			type : 'post',
			url : '/index.php?m=Home&c=User&a=do_login&t='+Math.random(),
			data : {username:username,password:password,referurl:referurl},
			dataType : 'json',
			success : function(res){
				if(res.status == 1){
					window.location.href = res.url;
				}else{
					layer.msg(res.msg, {
                            icon: 1,
                            time: 2000
                        });
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				//showErrorMsg('網絡失敗，請刷新頁面後重試');
				layer.msg('Network failed, please refresh the page and try again', {
                            icon: 1,
                            time: 2000
                        });
			}
		})

	}


    function checkEmail(str){
        var reg = /^[a-z0-9]([a-z0-9\\.]*[-_]{0,4}?[a-z0-9-_\\.]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+([\.][\w_-]+){1,5}$/i;
        if(reg.test(str)){
            return true;
        }else{
            return false;
        }
    }

</script>
</div>
</body>
</html>